package com.xiao.bargain.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.xiao.bargain.entity.BarginHuodongEntity;
import com.xiao.bargain.service.BarginHuodongService;
import com.xiao.group.common.utils.PageUtils;
import com.xiao.group.common.utils.R;



/**
 * 
 *
 * @author 韩国涛
 * @email 2845009006@gmail.com
 * @date 2021-09-21 20:37:53
 */
@RestController
@RequestMapping("bargain/barginhuodong")
public class BarginHuodongController {
    @Autowired
    private BarginHuodongService barginHuodongService;



    //创建活动
    @RequestMapping("tohd")
    public Integer tohd(@RequestParam("userId")Integer userId,
                  @RequestParam("barinId")Integer barinId){
        return barginHuodongService.tohd(barinId,userId);
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = barginHuodongService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info")
    public BarginHuodongEntity info(@RequestParam("barinId")Integer barinId,
                                                             @RequestParam("userId")Integer userId){
       return barginHuodongService.info(barinId, userId);
    }
    @RequestMapping("/infoss")
    public R infoss(@RequestParam("barinId")Integer barinId,
                                    @RequestParam("userId")Integer userId){
       return barginHuodongService.infoss(barinId, userId);
    }
    @RequestMapping("/infos")
    public BarginHuodongEntity info(@RequestParam("barinId")Integer barinId){
        BarginHuodongEntity info = barginHuodongService.getById(barinId);
        return info;
    }
    /**
     * 参与砍价
     */
    @RequestMapping("tobargain")
    public R tobargain(@RequestParam("mid")Integer mid,
                       @RequestParam("userId")Integer userId){
        return barginHuodongService.tobargain(mid,userId);
    }
    @RequestMapping("testbar")
    public R testbar(@RequestParam("barinId")Integer barinId,
                       @RequestParam("userId")Integer userId){
        return barginHuodongService.testbar(barinId,userId);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody BarginHuodongEntity barginHuodong){
		barginHuodongService.save(barginHuodong);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody BarginHuodongEntity barginHuodong){
		barginHuodongService.updateById(barginHuodong);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] moveIds){
		barginHuodongService.removeByIds(Arrays.asList(moveIds));

        return R.ok();
    }

}
